<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class FlowInside extends Model
{
    protected $table = 'flow_inside';

    protected $fillable = [
    	'order_systemnumber',
    	'purchase_weight',
    	'discharge_weight',
        'pick_weight',
    	'is_void',
    	'is_return',
    	'is_go',
    	'remarks'
    ];

    protected $appends = [
    	'relative_weight',
    	'is_return_desc',
    	'is_go_desc'
    ];

    

    const IS_GO_ZERO = '0';

    const IS_GO_ONE = '1';

    public static $IS_GO = [
    	self::IS_GO_ZERO => '不允许出门',
    	self::IS_GO_ONE => '允许出门'
    ];

    const IS_RETURN_ZERO = '0';

    const IS_RETURN_ONE = '1';

    public static $IS_RETURN = [
    	self::IS_RETURN_ZERO => '否',
    	self::IS_RETURN_ONE => '是'
    ];

    public function getRelativeWeightAttribute(){
    	if(array_key_exists('purchase_weight', $this->attributes)){
    		if(array_key_exists('discharge_weight', $this->attributes)){
    			return $this->attributes['relative_weight'] = $this->attributes['purchase_weight']-$this->attributes['discharge_weight'];
    		}
    	}
    }


    public function getIsGoDescAttribute(){
    	if(array_key_exists('is_go', $this->attributes)){
    		return $this->attributes['is_go_desc'] = self::$IS_GO[$this->attributes['is_go']];
    	}
    }

    public function getIsReturnDescAttribute(){
    	if(array_key_exists('is_return', $this->attributes)){
    		return $this->attributes['is_return_desc'] = self::$IS_RETURN[$this->attributes['is_return']];
    	}
    }
}
